#!/usr/bin/env python3

# -*- coding: utf-8 -*-

# @author: zhangbo

# @time: 2025/3/3 10:07
import os

from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from utils.tools import get_project_name, sep


class DriverConfig:

    def edge_Driver_Config(self):
        """
        edge 浏览器配置
        :return:
        """

        # self.url = "https://registry.npmmirror.com/-/binary/edgedriver"
        # # 这个链接无用
        # self.latest_release_url = "https://registry.npmmirror.com/-/binary/edgedriver/LATEST_RELEASE"

        executable_path = os.sep.join([get_project_name(), r"driver_file\msedgedriver.exe"])
        options = webdriver.EdgeOptions()
        # 设置窗口大小，设置为1920*1080
        options.add_argument("window-size=1920,1080")
        # 去除浏览器 正受到自动控制显示
        options.add_experimental_option("excludeSwitches", ["enable-automation"])
        # 解决selenium无法访问https的问题
        options.add_argument("--ignore-certificate-errors")
        # 允许忽略localhost上的TLS/SSL错误
        options.add_argument("--allow-insecure-localhost")
        # 设置为无痕模式
        options.add_argument("--incognito")
        # 设置为 无头模式
        # options.add_argument("--headless")
        # 解决卡顿
        options.add_argument("--disable-gpu")
        options.add_argument("--no-sandbox")
        options.add_argument("--disable-dev-shm-usage")

        service = webdriver.EdgeService(executable_path=executable_path)

        # webdriver-manager 自动管理driver_file 文件
        # driver = webdriver.Edge(
        #     EdgeChromiumDriverManager(url=self.url, latest_release_url=self.latest_release_url, cache_manager=365).install(),
        #     options=options)

        driver = webdriver.Edge(service=service, options=options)
        driver.maximize_window()

        # 删除所有的cookies
        # driver.delete_all_cookies()

        return driver
